<?php

namespace App\Livewire;

use Filament\Schemas\Components\Group;
use Filament\Schemas\Components\Icon;
use Filament\Schemas\Components\Image;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Text;
use Filament\Schemas\Components\UnorderedList;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Filament\Support\Enums\FontFamily;
use Filament\Support\Enums\FontWeight;
use Filament\Support\Enums\TextSize;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\HtmlString;
use Livewire\Component;

class PrimesDemo extends Component implements HasSchemas
{
    use InteractsWithSchemas;

    public function primes(Schema $schema): Schema
    {
        return $schema
            ->components([
                Group::make()
                    ->id('example')
                    ->extraAttributes([
                        'class' => 'py-16 px-[18rem] max-w-5xl',
                    ])
                    ->dense()
                    ->schema([
                        Text::make('Scan this QR code with your authenticator app:')
                            ->color('neutral'),
                        Image::make(
                            url: fn (): string => $this->getQrCodeUrl(),
                            alt: 'QR code to scan with an authenticator app',
                        )
                            ->imageHeight('12rem')
                            ->alignCenter(),
                        Section::make()
                            ->schema([
                                Text::make('Please save the following recovery codes in a safe place. They will only be shown once, but you\'ll need them if you lose access to your authenticator app:')
                                    ->weight(FontWeight::Bold)
                                    ->color('neutral'),
                                UnorderedList::make(fn (): array => array_map(
                                    fn (string $recoveryCode): \Filament\Schemas\Components\Component => Text::make($recoveryCode)
                                        ->fontFamily(FontFamily::Mono)
                                        ->size(TextSize::ExtraSmall)
                                        ->color('neutral'),
                                    [
                                        'tYRnCqNLUx-3QOLNKyDiV',
                                        'cKok2eImKc-oWHHH4VhNe',
                                        'C0ZstEcSSB-nrbyk2pv8z',
                                        '49EXLRQ8MI-FpWywpSDHE',
                                        'TXjHnvkUrr-KuiVJENPmJ',
                                        'BB574ookll-uI20yxP6oa',
                                        'BbgScF2egu-VOfHrMtsCl',
                                        'cO0dJYqmee-S9ubJHpRFR',
                                    ],
                                ))
                                    ->size(TextSize::ExtraSmall),
                            ])
                            ->compact()
                            ->secondary(),
                    ]),
                Group::make()
                    ->id('text')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Modifying these permissions may give users access to sensitive information.'),
                    ]),
                Group::make()
                    ->id('textHtml')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make(new HtmlString('<strong>Warning:</strong> Modifying these permissions may give users access to sensitive information.')),
                    ]),
                Group::make()
                    ->id('textColor')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Information')
                            ->color('info'),
                    ]),
                Group::make()
                    ->id('textNeutral')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Modifying these permissions may give users access to sensitive information.'),
                        Text::make('Modifying these permissions may give users access to sensitive information.')
                            ->color('neutral'),
                    ]),
                Group::make()
                    ->id('textBadge')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Warning')
                            ->color('warning')
                            ->badge(),
                    ]),
                Group::make()
                    ->id('textBadgeIcon')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Warning')
                            ->color('warning')
                            ->badge()
                            ->icon(Heroicon::ExclamationTriangle),
                    ]),
                Group::make()
                    ->id('textLarge')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Modifying these permissions may give users access to sensitive information.')
                            ->size(TextSize::Large),
                    ]),
                Group::make()
                    ->id('textBold')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('Modifying these permissions may give users access to sensitive information.')
                            ->weight(FontWeight::Bold),
                    ]),
                Group::make()
                    ->id('textMono')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('28o.-AK%D~xh*.:[4"3)zPiC')
                            ->fontFamily(FontFamily::Mono),
                    ]),
                Group::make()
                    ->id('textTooltip')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Text::make('28o.-AK%D~xh*.:[4"3)zPiC')
                            ->tooltip('Your secret recovery code'),
                    ]),
                Group::make()
                    ->id('icon')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Icon::make(Heroicon::Star),
                    ]),
                Group::make()
                    ->id('iconColor')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Icon::make(Heroicon::ExclamationCircle)
                            ->color('danger'),
                    ]),
                Group::make()
                    ->id('iconTooltip')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Icon::make(Heroicon::ExclamationTriangle)
                            ->tooltip('Warning'),
                    ]),
                Group::make()
                    ->id('image')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Image::make(
                            url: fn (): string => $this->getQrCodeUrl(),
                            alt: 'QR code to scan with an authenticator app',
                        ),
                    ]),
                Group::make()
                    ->id('imageSize')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Image::make(
                            url: fn (): string => $this->getQrCodeUrl(),
                            alt: 'QR code to scan with an authenticator app',
                        )
                            ->imageHeight('12rem'),
                    ]),
                Group::make()
                    ->id('imageAlignment')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Image::make(
                            url: fn (): string => $this->getQrCodeUrl(),
                            alt: 'QR code to scan with an authenticator app',
                        )
                            ->alignCenter(),
                    ]),
                Group::make()
                    ->id('imageTooltip')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        Image::make(
                            url: fn (): string => $this->getQrCodeUrl(),
                            alt: 'QR code to scan with an authenticator app',
                        )
                            ->tooltip('Scan this QR code with your authenticator app')
                            ->alignCenter(),
                    ]),
                Group::make()
                    ->id('unorderedList')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        UnorderedList::make([
                            'Tables',
                            'Schemas',
                            'Actions',
                            'Notifications',
                        ]),
                    ]),
                Group::make()
                    ->id('unorderedListLarge')
                    ->extraAttributes([
                        'class' => 'p-16 max-w-xl',
                    ])
                    ->schema([
                        UnorderedList::make([
                            Text::make('Tables')->size(TextSize::Large),
                            Text::make('Schemas')->size(TextSize::Large),
                            Text::make('Actions')->size(TextSize::Large),
                            Text::make('Notifications')->size(TextSize::Large),
                        ])
                            ->size(TextSize::Large),
                    ]),
            ]);
    }

    public function render()
    {
        return view('livewire.primes');
    }

    protected function getQrCodeUrl(): string
    {
        return '';
    }
}
